<?php
if(!defined('main')) {
die("Kein Zutritt"); }

#### U R L   a u s l e s e n
function url() {
   
    $ar = array();
    if ( isset($_SERVER['QUERY_STRING']) ) {
      $q = $_SERVER['QUERY_STRING'];
      $q = preg_replace("/[^a-z0-9-_\&=]/i","",$q);
      $fu = strpos ($q,'&');
      $fi = strpos ($q,'=');
      $ende = strlen ($q);

      if ( $fi !== FALSE AND $fu !== FALSE ) {
        if ( $fu < $fi ) {
          $ende = $fu;
        } elseif ( $fi < $fu ) {
          $ende = $fi;
        }
      } elseif ($fu !== FALSE) {
        $ende = $fu;
      } elseif ($fi !== FALSE) {
        $ende = $fi;
      }
      $qs = substr($q,0,$ende);
      $ar = explode('-',$qs);
	  $url = $ar[0];
	  }
	  return $url;
}

### URL para

function urlpara($para) {
   
    $ar = array();
    if ( isset($_SERVER['QUERY_STRING']) ) {
      $q = $_SERVER['QUERY_STRING'];
      $q = preg_replace("/[^a-z0-9-_\&=]/i","",$q);
      $fu = strpos ($q,'&');
      $fi = strpos ($q,'=');
      $ende = strlen ($q);

      if ( $fi !== FALSE AND $fu !== FALSE ) {
        if ( $fu < $fi ) {
          $ende = $fu;
        } elseif ( $fi < $fu ) {
          $ende = $fi;
        }
      } elseif ($fu !== FALSE) {
        $ende = $fu;
      } elseif ($fi !== FALSE) {
        $ende = $fi;
      }
      $qs = substr($q,0,$ende);
      $ar = explode('-',$qs);
	  }
	  return $ar[$para];
}

### Z e i c h e n   C h e c k
    function check_string($string) {
                
        // erlaubte zeichen a-z,A-Z,0-9
                
        if((preg_match('/^[a-zA-Z0-9]+$/',$string))) return true;
                
        return false;
            
    }

#### C o o k i e

function goodcookie() {


	
	if ( isset($_SESSION[user]) AND isset($_SESSION[password]) AND isset($_SESSION[rank]) AND isset($_COOKIE[($gamename . "_user")]) AND isset($_COOKIE[($gamename . "_password")]) ) {
	
	return true;
	
	} else {
	
	   if ( isset($_SESSION[user]) AND isset($_SESSION[password]) AND isset($_SESSION[rank]) ) {
			 setcookie(($gamename . "_user"), $_SESSION[user], time()+3600*24*7);
			 setcookie(($gamename . "_password"), md5($_SESSION[password]), time()+3600*24*7);
			 
			 return true;
	    } else {
	
			if ( isset($_COOKIE[$gamename . "_user"]) AND isset($_COOKIE[$gamename . "_password"]) ) {
				
				$erg = db_query("SELECT * FROM users WHERE username = '" . $_COOKIE[$gamename . "_user"] . "' AND gameid = '" . $gameid . "'");
				while($row = db_fetch_assoc($erg)) {
				
				if ( $row['username'] == $_COOKIE[$gamename . "_user"] AND md5($row['password']) == $_COOKIE[$gamename . "_password"] )
				$_SESSION[user] = $row['username'];
		 	 	$_SESSION[password] = $row['password'];
		 	 	$_SESSION[rank] = $row['rank'];
				
				return true;
				}
				
   		 	}	
	
	   } 
	
	}

}





?>
